// pages/start/start.js
var data = require("../../utiliz/data.js")
var show = require("../../utiliz/show.js")

var mouseType="first";
var catType = "first";
var maxheight = 1000;
var maxwidth =750;
var widths = [];
var heights = [];
var colNumber = 25;
var rowNumber = 40;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    luckyflag:false,
    tapStart:false,
    btn_text:"Start",
    catType:[{
      type: "first",
      text: "No1",
      checked: true,
      url1:'/images/catU1.png',//
      url2:'/images/catD1.png',//
      url3:'/images/catL1.png',//
      url4:'/images/catR1.png'//
    },{
        type: "second",
        text: "No2",
        checked: false,
        url1: '/images/catU2.png',//
        url2: '/images/catD2.png',//
        url3: '/images/catL2.png',//
        url4: '/images/catR2.png'//
    }],
    mouseType: [{
      type: "first",
      text: "No1",
      checked: true,
      url1: '/images/mU.png',//
      url2: '/images/mD.png',//
      url3: '/images/mL.png',//
      url4: '/images/mR.png'//
    }, {
      type: "second",
      text: "No2",
      checked: false,
        url1: '/images/mU2.png',//
        url2: '/images/mD2.png',//
        url3: '/images/mL2.png',//
        url4: '/images/mR2.png'//
    }],
    initWH:[2,1],
    widths:[1,2,3],
    heights:[1,2,3],
    colNumber:colNumber,
    rowNumber:rowNumber
  },
  backToGame: function(){
    wx.navigateTo({
      url: '../index/index?type=noting',
    })
  },
  startGame: function(){
    this.setData({
      tapStart:true,
      btn_text:"Restart"
    })
    show.changeCatType(catType);
    show.changeMouseType(mouseType);
    console.log(catType,mouseType)
    wx.navigateTo({
      url: '../index/index?type=init' + "&row=" + rowNumber + "&col=" + colNumber
    })
  },
  mouseTap: function(e){
    var str = e.currentTarget.dataset.type;
    var temp = this.data.mouseType;
    mouseType = e.currentTarget.dataset.type;
    if (str == "first") {
      temp[0].checked = true;
      temp[1].checked = false;

      this.setData({
        mouseType: temp
      })
    }
    else if (str == "second") {
      temp[0].checked = false;
      temp[1].checked = true;
      this.setData({
        mouseType: temp
      })
    }
  },
  tapcheck: function (e) {
    var str=e.currentTarget.dataset.type;
    var temp = this.data.catType;
    catType = e.currentTarget.dataset.type;
    if(str=="first")
    {
      temp[0].checked=true;
      temp[1].checked=false;
      
      this.setData({
        catType:temp
      })
    }
    else if(str=="second")
    {
      temp[0].checked = false;
      temp[1].checked = true;
      this.setData({
        catType: temp
      })
    }
  },

  bindChange: function (e) {
    const val = e.detail.value
    var temp = parseInt((maxheight / (maxwidth / colNumber))); 
    heights=[];
    for (var j = temp - 15; j <= temp; j++)
      heights.push(j);
    
    colNumber = widths[val[0]];
    rowNumber = heights[val[1]];
    this.setData({
      heights: heights,
      colNumber:colNumber,
      rowNumber:rowNumber,
      luckyflag: false
    });

    if(colNumber==31&&rowNumber==40)
    {
      this.setData({
        luckyflag:true
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    for(var i=15;i<=35;i++)
      widths.push(i);
    var temp=parseInt((maxheight/(maxwidth/20)));
    for(var j=temp-15;j<=temp;j++)
      heights.push(j);
    this.setData({
      widths:widths,
      heights:heights
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})